package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortString {
    public static void main(String[] args) {
        /*
        List<String> list  = new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");
        System.out.println("list原始数据："+list);
//对英文字符串进行排序的时候，会按照首字母的ASCII码进行排序
        //若首字母相同，则按照第二个字母的ASCII码进行排序，以此类推
        Collections.sort(list);
        System.out.println("list排序后："+list);

         */
        List<String> list = new ArrayList<>();
        list.add("吴羽呜呜呜");
        list.add("李四维");
        list.add("王五哥哥");
        list.add("张三");
        System.out.println("list原始数据：" + list);
        Collections.sort(list);
        System.out.println("list排序后：" + list);

        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.length() - o2.length();//升序
                //return o2.length() - o1.length();//降序
            }
        });
        System.out.println("list排序后：" + list);
        Collections.sort(list, (o1, o2) -> o1.length() - o2.length());
        System.out.println("list排序后：" + list);
    }
}
